﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace nLearning
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Zyg40.Database.ConnectServer.ConnectionString = Query.SQLConnectionString("192.168.1.103","sa","nextwaver","Business_Knowledge");
            //Zyg40.Database.ConnectServer.ConnectionString = Query.SQLConnectionString("122.155.190.7", "jigsaw", "TEERAman659", "DB_Jigsaw");
        }

        private void txtBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Return)
            {
                RoutedEventArgs miss = null;
                btEnter_Click(sender, miss);
            }
        }

        private void btEnter_Click(object sender, RoutedEventArgs e)
        {
            string value = txtBox.Text.Trim();
            if (value != Warehouse.EXIT_CODE)
            {
                #region do something
                //--login here
                if (LearningLib.Login(value))
                {
                    //end login and open course--
                    //txtBox.Clear();
                    //Course cours = new Course();
                    //cours.Topmost = true;
                    //cours.Show();
                }
                else
                {
                    Message.Error("ทดสอบระบบ");
                    Message.Info(cString.ID("login.fail"));
                    txtBox.Clear();
                }
                #endregion
            }
            else if (value == Warehouse.EXIT_CODE)
            {
                this.Close();
            }
        }

        private void flag_display_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (TH_flag.Visibility == System.Windows.Visibility.Visible)
            {
                TH_flag.Visibility = System.Windows.Visibility.Hidden;
                UK_flag.Visibility = System.Windows.Visibility.Visible;
                Warehouse.CURRENT_LANGUAGE = Warehouse.Lang.Eng;
            }
            else
            {
                TH_flag.Visibility = System.Windows.Visibility.Visible;
                UK_flag.Visibility = System.Windows.Visibility.Hidden;
                Warehouse.CURRENT_LANGUAGE = Warehouse.Lang.Tha;
            }
        }

        private void flag_display_MouseUp(object sender, TouchEventArgs e)
        {
            MouseButtonEventArgs n = null;
            flag_display_MouseUp(sender, n);
        }
    }
}
